<?
require_once('ConverterBase.php');

class ArrayConverter extends ConverterBase {
	private $delimiter= ';';
	
	public function setDelimiter($value) { $this->delimiter= $value; return $this; }
	public function getDelimiter() { return $this->delimiter; }
	
	protected function toDatatype($string) {
		if (empty($string)) return array();
		if (is_array($string)) return $string;
		return split($this->getDelimiter(),$string);
	}
	protected function toString($object) {
		if (is_null($object)) return '';
		if (!is_array($object))
			throw new ConverterException($this,'array_expected');
		return implode($this->getDelimiter(),$object);
	}
}
